package cm.cool.web.service.bill;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cm.cool.web.bean.Bill;
import cm.cool.web.data.BillMapper;
import cm.cool.web.util.respon.PaginationDto;
import cm.cool.web.util.respon.R;
import cm.cool.web.util.respon.ResultEncoding;

/**
 * 条件查找交易记录
 * @author fangzhenxing
 */
@Service
public class BillService {

	@Autowired
	private BillMapper billMapper;

	/**
	 * 条件查找交易记录
	 * @return
	 */
	public R findUserNameBill(Bill bill, PaginationDto paginationDto) {
		R r = new R();

		try {
			PageHelper.startPage(paginationDto.getCurrentPageNum(), paginationDto.getPerPageSize());
			paginationDto.setEntitys(billMapper.findUserNameBill(bill));
			int count = billMapper.findUserNameBillCount(bill);
			paginationDto.setTotalCount(count);
			paginationDto.setTotalPageNum((int)Math.ceil((count*1.0) / paginationDto.getPerPageSize()));
			r.setData(paginationDto);
		} catch (Exception e) {
			e.printStackTrace();
			r.setCode(ResultEncoding.R_ERR);
			r.setMsg("查询异常");
			return r;
		}

		return r;
	}

}
